package com.yeban.javase.day07.test04_reg;

import java.util.Scanner;

/**
 * @Desc TODO
 * @Author yeban
 * @Date 2025/10/15
 *
 * 7.密码强度校验，控制台输入字符串，判断其弱、中、强（数字+字母+特殊符号）
 */
public class Test007 {

    public static void main(String[] args) {
        System.out.print("请输入密码：");
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();

        int hasDigital = 0;
        int hasCase = 0;
        int hasSymple = 0;

        // 判断密码强弱
        String[] arr = str.split("");
        for (int i = 0; i < arr.length; i++) {
            if(arr[i].matches("[0-9]")){    //判断是否有数字
                hasDigital = 1;
            } else if (arr[i].matches("[a-zA-Z]")){ //判断是否有字母
                hasCase = 1;
            } else if(arr[i].matches("[^0-9a-zA-Z]")){    //判断是否有特殊符号
                hasSymple = 1;
            }
        }

        int type = hasDigital + hasCase + hasSymple;

        if(type == 1){
            System.out.println("\"" + str + "\"：密码强度为弱！");
        } else if(type == 2){
            System.out.println("\"" + str + "\"：密码强度为中！");
        } else if(type == 3){
            System.out.println("\"" + str + "\"：密码强度为强！");
        } else {
            System.out.println("密码不能为空！");
        }

    }
}
